package com.daigoudao.web.service.impl;

import com.daigoudao.web.dao.IAccountDao;
import com.daigoudao.web.model.AccountModel;
import com.daigoudao.web.service.IAccountService;

public class AccountServiceImpl implements IAccountService {

	private IAccountDao accountDao;

	public IAccountDao getAccountDao() {
		return accountDao;
	}

	public void setAccountDao(IAccountDao accountDao) {
		this.accountDao = accountDao;
	}

	@Override
	public AccountModel getAccountInfo(int userid) {
		AccountModel accountModel = accountDao.getAccountByUserID(userid);
		if (accountModel == null) {
			accountModel = new AccountModel();
			accountModel.setAccountType(0);
			accountModel.setUserid(userid);
			accountDao.addAccountInfo(accountModel);
		}
		return accountModel;
	}

	@Override
	public void saveAccountInfo(AccountModel accountModel) {
		
		
		int accountType = accountModel.getAccountType();
		if (accountType == 1) {
			try {
				accountDao.saveAccountInfo4Alipay(accountModel);
			} catch (Exception e) {

			}
		} else {
			accountDao.saveAccountInfo4Bank(accountModel);
		}
	}

}
